From 4a086b35c00492da544ebe0851ac12c85461bfd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 24 Nov 2009 01:04:38 +0000 Subject: [PATCH] Removed two function calls in common path Re-arranged code making babl_process and babl_fish_process reside in babl-path-fish.c, where babl_fish_process and babl_fish_path_process can be inlined with babl_process(). --- babl/babl-fish-path.c | 88 +++++++++++++++++++++++++++++++++++++++---- babl/babl-fish.c | 47 ----------------------- babl/babl-internal.c | 35 ----------------- babl/babl-internal.h | 8 ---- 4 files changed, 81 insertions(+), 97 deletions(-) diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index 10ce65d..08667cf 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -301,25 +301,99 @@ babl_fish_path (const Babl *source, return babl; } -long +static long babl_fish_path_process (Babl *babl, void *source, void *destination, long n) { - long ret; - - babl_assert (source); - babl_assert (destination); - - ret = process_conversion_path (babl->fish_path.conversion_list, + return process_conversion_path (babl->fish_path.conversion_list, source, destination, n); +} + + +static long +babl_fish_process (Babl *babl, + void *source, + void *destination, + long n) +{ + long ret = 0; + + switch (babl->class_type) + { + case BABL_FISH_REFERENCE: + if (babl->fish.source == babl->fish.destination) + { /* XXX: we're assuming linear buffers */ + memcpy (destination, source, n * babl->fish.source->format.bytes_per_pixel); + ret = n; + } + else + { + ret = babl_fish_reference_process (babl, source, destination, n); + } + break; + + case BABL_FISH_SIMPLE: + if (BABL (babl->fish_simple.conversion)->class_type == BABL_CONVERSION_LINEAR) + { + ret = babl_conversion_process (BABL (babl->fish_simple.conversion), + source, destination, n); + } + else + { + babl_fatal ("Cannot use a simple fish to process without a linear conversion"); + } + break; + + case BABL_FISH_PATH: + ret = babl_fish_path_process (babl, source, destination, n); + break; + + default: + babl_log ("NYI"); + ret = -1; + break; + } + return ret; } +long +babl_process (Babl *babl, + void *source, + void *destination, + long n) +{ + babl_assert (babl); + babl_assert (source); + babl_assert (destination); + babl_assert (BABL_IS_BABL (babl)); + if (n == 0) + return 0; + babl_assert (n > 0); + + /* first check if it is a fish since that is out fast path */ + if (babl->class_type >= BABL_FISH || + babl->class_type <= BABL_FISH_PATH) + { + babl->fish.processings++; + return babl->fish.pixels += + babl_fish_process (babl, source, destination, n); + } + + /* matches all conversion classes */ + if (babl->class_type >= BABL_CONVERSION && + babl->class_type <= BABL_CONVERSION_PLANAR) + return babl_conversion_process (babl, source, destination, n); + + babl_fatal ("eek"); + return -1; +} + static long process_conversion_path (BablList *path, void *source_buffer, diff --git a/babl/babl-fish.c b/babl/babl-fish.c index d2cda12..a09efaf 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -278,53 +278,6 @@ babl_fish (const void *source, } } -long -babl_fish_process (Babl *babl, - void *source, - void *destination, - long n) -{ - long ret = 0; - - switch (babl->class_type) - { - case BABL_FISH_REFERENCE: - if (babl->fish.source == babl->fish.destination) - { /* XXX: we're assuming linear buffers */ - memcpy (destination, source, n * babl->fish.source->format.bytes_per_pixel); - ret = n; - } - else - { - ret = babl_fish_reference_process (babl, source, destination, n); - } - break; - - case BABL_FISH_SIMPLE: - if (BABL (babl->fish_simple.conversion)->class_type == BABL_CONVERSION_LINEAR) - { - ret = babl_conversion_process (BABL (babl->fish_simple.conversion), - source, destination, n); - } - else - { - babl_fatal ("Cannot use a simple fish to process without a linear conversion"); - } - break; - - case BABL_FISH_PATH: - ret = babl_fish_path_process (babl, source, destination, n); - break; - - default: - babl_log ("NYI"); - ret = -1; - break; - } - - return ret; -} - static int diff --git a/babl/babl-internal.c b/babl/babl-internal.c index eac0a95..49a9010 100644 --- a/babl/babl-internal.c +++ b/babl/babl-internal.c @@ -75,40 +75,6 @@ babl_die (void) exit (-1); } -long -babl_process (Babl *babl, - void *source, - void *destination, - long n) -{ - babl_assert (babl); - babl_assert (source); - babl_assert (destination); - babl_assert (BABL_IS_BABL (babl)); - if (n == 0) - return 0; - babl_assert (n > 0); - - /* matches all conversion classes */ - if (babl->class_type >= BABL_CONVERSION && - babl->class_type <= BABL_CONVERSION_PLANAR) - return babl_conversion_process (babl, source, destination, n); - - if (babl->class_type == BABL_FISH || - babl->class_type == BABL_FISH_REFERENCE || - babl->class_type == BABL_FISH_PATH || - babl->class_type == BABL_FISH_SIMPLE) - { - long ret; - ret = babl_fish_process (babl, source, destination, n); - babl->fish.processings++; - babl->fish.pixels += ret; - return ret; - } - - babl_fatal ("eek"); - return -1; -} BablMutex *babl_format_mutex; #if BABL_DEBUG_MEM @@ -123,7 +89,6 @@ babl_internal_init (void) babl_format_mutex = babl_mutex_new (); #if BABL_DEBUG_MEM babl_debug_mutex = babl_mutex_new (); - fprintf (stderr, "%p %p\n", babl_debug_mutex, babl_format_mutex); #endif } diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 451c5f8..70538e9 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -81,10 +81,6 @@ void babl_set_extender (Babl *new_extender); Babl * babl_extension_quiet_log (void); -long babl_fish_process (Babl *babl, - void *source, - void *destination, - long n); long babl_fish_reference_process (Babl *babl, BablImage *source, BablImage *destination, @@ -98,10 +94,6 @@ void babl_fish_stats (FILE *file); Babl * babl_fish_path (const Babl *source, const Babl *destination); -long babl_fish_path_process (Babl *babl, - void *source, - void *destination, - long n); int babl_fish_get_id (const Babl *source, const Babl *destination); -- 2.30.2